//
//  MyPromise.h
//  PromiseText
//
//  Created by mac123 on 2019/2/19.
//  Copyright © 2019年 wjh. All rights reserved.
//


/**
static inline
void after(int delay ,void(^block)(void)){
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        block();
    });
}

-(void)sssss {
    [[MyPromise first:^(PassBlock  _Nonnull pass) {
        NSLog(@"1");
        after(3, ^{
            pass(@"111");
        });
    }].then(^(id  _Nonnull data, PassBlock  _Nonnull pass) {
        NSLog(@"2：接受值%@",data);
        after(1, ^{
            pass(@"222");
        });
    }).then(^(id  _Nonnull data, PassBlock  _Nonnull pass) {
        NSLog(@"3：接受值%@",data);
        after(4, ^{
            pass(@"333");
        });
    }).then(^(id  _Nonnull data, PassBlock  _Nonnull pass) {
        NSLog(@"4：接受值%@",data);
    }) start];
}
*/


#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class MyPromise;
typedef void(^CatchErrBlock)(NSError *err);
typedef void(^PassBlock)(id obj);
typedef void(^Adapter)(id data,PassBlock pass);
typedef void(^FirsBlock)(PassBlock pass);
@interface MyPromise : NSObject

/** 首先使用firstblock创建 MyPromise对象*/
+(MyPromise *)first:(FirsBlock)block;

/** then方法延续链接 */
@property (nonatomic ,copy ,readonly) MyPromise*(^then)(Adapter adapter);

/** 错误接收 */
@property (nonatomic ,copy ,readonly) MyPromise*(^catchError)(CatchErrBlock errBlock);

/** 开始执行启动 */
-(void)start;

@end

NS_ASSUME_NONNULL_END
